package com.gzxx.service.impl;

import com.gzxx.domain.po.SysUserDept;
import com.gzxx.mapper.SysUserDeptMapper;
import com.gzxx.service.SysUserDeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

/**
 * SysUserDeptServiceImpl
 *
 * @author chenjing
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Transactional(readOnly = true, rollbackFor = Exception.class, timeout = 5)
public class SysUserDeptServiceImpl implements SysUserDeptService {

    private final SysUserDeptMapper sysUserDeptMapper;

    @Transactional(rollbackFor = Exception.class, timeout = 5)
    @Override
    public void updateUserDept(SysUserDept sysUserDept) {
        if (!ObjectUtils.isEmpty(sysUserDept)) {
            // 先删除
            sysUserDeptMapper.deleteByUserId(sysUserDept.getUserId());
            // 再新增
            sysUserDeptMapper.insert(sysUserDept);
        }
    }
}
